package WWW.SST.LIB;

import MOLE.*;

/** 
 Get_BonusNumber ��ժҪ˵����
*/
public class Get_BonusNumber
{
	public Get_BonusNumber()
	{
		//
		// TODO: �ڴ˴���ӹ��캯���߼�
		//

	}

	public final void DownNum()
	{
		FtpLib ftp = new FtpLib();
		int s = (new MOLE.Bill.Term(0)).TermInIntFormat;
		String s_qihao = java.time.LocalDateTime.Today.toString("yyyyMMdd");
		if (s <= 10 && s>1)
		{
			s_qihao += "0" + (String.valueOf(s);
		}
		else if (s > 10)
		{
			s_qihao += (String.valueOf(s);
		}
		else if (s == 1)
		{
			s_qihao += String.valueOf(s);
		}
		try
		{


			String localFile = MOLE.GetValue.GetConfigString("FtpFile") + s_qihao + ".txt";
			if (!(new java.io.File(localFile)).isFile())
			{
//					ftp.setRemoteHost(MOLE.GetValue.GetConfigString("FtpUrl"));
//					ftp.setRemoteUser(MOLE.GetValue.GetConfigString("FtpUser"));
//					ftp.setRemotePass(MOLE.GetValue.GetConfigString("FtpPwd"));
				ftp.setRemoteHost("222.177.14.204");
				ftp.setRemoteUser("test1");
				ftp.setRemotePass("test1");
				ftp.login();
				ftp.download(s_qihao + ".txt", localFile, true);
				MOLE.file.write("e:\\log\\bet_log.txt", "FTP MSG:download ok------" + java.time.LocalDateTime.now() + "\r\n");
			}
			else
			{
				java.io.File fio = new java.io.File(localFile);
				if (fio.length() == 0)
				{
//						ftp.setRemoteHost(MOLE.GetValue.GetConfigString("FtpUrl"));
//						ftp.setRemoteUser(MOLE.GetValue.GetConfigString("FtpUser"));
//						ftp.setRemotePass(MOLE.GetValue.GetConfigString("FtpPwd"));
					ftp.setRemoteHost("222.177.14.204");
					ftp.setRemoteUser("test1");
					ftp.setRemotePass("test1");
					ftp.login();
					ftp.download(s_qihao + ".txt", localFile, true);
					MOLE.file.write("e:\\log\\bet_log.txt", "FTP MSG:download ok------" + java.time.LocalDateTime.now() + "\r\n");
				}
				else
				{
					MOLE.file.write("e:\\log\\bet_log.txt", "FTP MSG:file exists!------" + java.time.LocalDateTime.now() + "\r\n");
				}
			}
							if ((new java.io.File(localFile)).isFile())
							{
								FileStream fs = File.OpenRead(localFile);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: byte[] data = new byte[fs.Length];
								byte[] data = new byte[fs.getLength()];
								fs.Read(data,0,data.length);
								System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
								String str = encoding.GetString(data);
								if (str.length() > 14)
								{
									str = str.substring(5, 14).replace(" ","");
									MOLE.SQLOS sqlos5 = new MOLE.SQLOS("Accont_Award_qihao");
									sqlos5.RS(s_qihao.insert(8,"-"));
									sqlos5.RS(str);
									sqlos5.ExecStoreProcess();
			//						MOLE.file.write(@"e:\log\bet_log.txt", s_qihao+"���������ȡ�ɹ�------"+System.DateTime.Now+"\r\n" );
									MOLE.file.write("e:\\log\\bet_log.txt", "BonusNumber Msg:" + s_qihao + "'BonusNumber  has been saved!!-------" + java.time.LocalDateTime.now() + "\r\n");
								}
								else
								{
									(new java.io.File(localFile)).delete();
			//						MOLE.file.write(@"e:\log\bet_log.txt", s_qihao+"����Ϊ��------"+System.DateTime.Now+"\r\n" );
									MOLE.file.write("e:\\log\\bet_log.txt", "BonusNumber Err:" + s_qihao + "'BonusNumber  is null!!-------" + java.time.LocalDateTime.now() + "\r\n");
								}
							}
							else
							{
			//					MOLE.file.write(@"e:\log\bet_log.txt", s_qihao+".txt�ļ�������------"+System.DateTime.Now+"\r\n" );
								MOLE.file.write("e:\\log\\bet_log.txt", "BonusNumber Err:" + s_qihao + "'BonusNumber file  is null!!-------" + java.time.LocalDateTime.now() + "\r\n");
							}
		}
		catch (RuntimeException e)
		{
			MOLE.file.write("e:\\log\\bet_log.txt", "FTP ERR:" + e.toString() + "------" + java.time.LocalDateTime.now() + "\r\n");
		}
		finally
		{
			ftp.close();
		}
	}
}